package com.baomidou.mybatisplus.samples.association.config;

import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
import com.baomidou.mybatisplus.samples.association.plugin.PluginUtils;
import com.baomidou.mybatisplus.samples.association.plugin.mapping.ParameterValueMapping;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.SQLException;
import java.util.List;

@Intercepts(
        @Signature(
                type = Executor.class,
                method = "update",
                args = {MappedStatement.class, Object.class}
        )
)
public class UserMybatisInterceptor implements InnerInterceptor {
    private static final Logger LOGGER = LoggerFactory.getLogger(UserMybatisInterceptor.class);


    @Override
    public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
        List<ParameterValueMapping> parameterValueMappingList = PluginUtils.getParameterValueMapping(ms.getConfiguration(), ms.getBoundSql(parameter));
        System.out.println("参数对象：" + parameterValueMappingList);
    }

    @Override
    public void beforeUpdate(Executor executor, MappedStatement ms, Object parameter) throws SQLException {
        List<ParameterValueMapping> parameterValueMappingList = PluginUtils.getParameterValueMapping(ms.getConfiguration(), ms.getBoundSql(parameter));
        System.out.println("参数对象：" + parameterValueMappingList);
    }

}
